import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'


import MainBanner from './components/MainBanner.vue'
import SmallBanner from './components/SmallBanner.vue'
import Main from './components/Main.vue'
import Article from './pages/Article.vue'
import Category from './pages/Category.vue'
import Bonus from './pages/Bonus.vue'
import Links from './pages/Links.vue'
import About from './pages/About.vue'
import Detail from './pages/Detail.vue'

Vue.config.productionTip = false
Vue.use(VueRouter)
// markdown插件
Vue.use(mavonEditor)

// 路由=================
const router = new VueRouter({
	routes: [
		{name: '', path: '/', redirect: 'index'},
		{name: '', path: '/index', components: {MainBanner:MainBanner, Main:Main}, props: {MainBanner: {slogan:'Serious Life'}}},
		{name: '', path: '/article', components: {SmallBanner:SmallBanner, Main:Article}, props: {SmallBanner: {slogan:'文章', proverb:'The quieter you become,The more you can hear.'}}},
		{name: '', path: '/category', components: {SmallBanner:SmallBanner, Main:Category}, props: {SmallBanner: {slogan:'分类', proverb:'___________________________________________'}}},
		{name: '', path: '/bonus', components: {SmallBanner:SmallBanner, Main:Bonus}, props: {SmallBanner: {slogan:'一万小时定律', proverb:'___________________________________________'}}},
		{name: '', path: '/links', components: {SmallBanner:SmallBanner, Main:Links}, props: {SmallBanner: {slogan:'友情链接', proverb:'___________________________________________'}}},
		{name: '', path: '/about', components: {SmallBanner:SmallBanner, Main:About}, props: {SmallBanner: {slogan:'寂寞是最好的增值期', proverb:'___________________________________________'}}},
		{name: '', path: '/detail/:year/:month/:day/:aid', components: {SmallBanner:SmallBanner, Main:Detail}},
	]
})
// <router-link to="/about"></router-link>
// =====================

new Vue({
	el: '#app',
	render: h => h(App),
	router: router,
	// 组件通信
	beforeCreate() {
		// 安装全局事件总线
		Vue.prototype.$bus = this
		Vue.prototype.url = 'https://116.62.185.204:13423/blog'
		Vue.prototype.toast = function(msg,duration) {
			duration=isNaN(duration)?3000:duration;
			var m = document.createElement('div');
			m.innerHTML = msg;
			m.style.cssText="max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 4px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: rgba(0, 0, 0,.7);font-size: 16px;";
			document.body.appendChild(m);
			setTimeout(function() {
					var d = 0.5;
					m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
					m.style.opacity = '0';
					setTimeout(function() { document.body.removeChild(m) }, d * 1000);
			}, duration);
		}
	}
})
